#ifndef _TASK_H
#define _TASK_H

#include "../StdAfx.h"

class Task{
public:
	Task(boost::function<void ()> f){
		mFunc = f;
	}
	~Task();
	boost::function<void ()> getFunction();
	void operator()(){
		mFunc();
	}
protected:
	boost::function<void ()> mFunc;
	friend Task* newTask(boost::function<void ()>);

};

inline Task* newTask(boost::function<void ()> f){
	return new Task(f);
}

class TaskExecutor
{
public:
	TaskExecutor(size_t nThreads);
	~TaskExecutor();
	void addTask(Task* task);
	void stop();
private:
	void runThread();
	bool mShutdown;
	std::list<Task*> mTaskList;
	std::vector<boost::thread*> mThreads;
	// Variables de sincronizacion
	boost::interprocess::interprocess_mutex mListMux;
	boost::interprocess::interprocess_condition mLoopCond;
};

#endif